<template>
  <div class="login">
    <el-card shadow="hover" header="登录界面">
      <el-form :label-position="labelPosition" label-width="60px" @submit.native.prevent="login">
        <el-form-item label="用户名">
          <el-input placeholder="请输入用户名..." v-model="model.username">用户名</el-input>
        </el-form-item>
        <el-form-item label="密码" >
          <el-input type="password" placeholder="请输入密码..." v-model="model.password">密码</el-input>
        </el-form-item>
        <el-form-item style="margin-left: 145px;">
          <el-button type="primary" native-type="submit">登录</el-button>
          <el-button type="primary" @click="$router.push('/register')">注册</el-button>
        </el-form-item>

      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name: "Login",
    data(){
      return{
        labelPosition:'right',
        model:{}
      }
    },
    methods:{
      async login(){
        const res = await this.$http.post('/login',this.model)
        localStorage.setItem('token',res.data.token)
        this.$router.push('/')
        this.$message.success('登录成功')
        console.log(res)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .login::before{
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    background-color: #c47c89;
    /*filter: blur(3px);*/
    z-index: -1;
    opacity: 0.4;
    /*background: url("../../assets/img/bg.jpg") no-repeat;*/
  }
  .el-card{
    width: 25rem;
    margin: 10rem auto;
    text-align: center;

  }
</style>
